<!DOCTYPE HTML>
<html lang="en">
<head>
    <title>欢迎注册Supermarket</title>
    <link rel="stylesheet" href="css/regist.css"/>
    <link rel="icon" type="image/x-icon" href="img/head/favicon.ico" />
    <noscript>抱歉，你的浏览器不支持 JavaScript!</noscript>
    <script type="text/javascript" src="js/common/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="js/regist_ajax.js"></script>
    <meta charset="UTF-8">
    <style>
        .button {
            display: inline-block;
            border-radius: 18px;
            background-color: #009992;
            border: none;
            color: #FFFFFF;
            text-align: center;
            font-size: 20px;
            padding: 8px;
            width: 100px;
            transition: all 0.5s;
            cursor: pointer;
            margin: -20px;
        }

        .button span {
            cursor: pointer;
            display: inline-block;
            position: relative;
            transition: 0.5s;
        }

        .button span:after {
            content: '»';
            position: absolute;
            opacity: 0;
            top: 0;
            right: 60px;
            transition: 0.5s;
        }

        .button:hover span {
            padding-right: 25px;
        }

        .button:hover span:after {
            opacity: 1;
            right: 0;
        }
    </style>
</head>
<body>
<img src="./img/head/logo.png" alt="logo" style="position: absolute;top: 8%;left: 12%;">
<form id="myForm"  onsubmit="return register(this);">
    <h1>欢迎注册网上商城</h1>
    <table>
        <tr>
            <td colspan="2" id="alert" class="tds" style="text-align: center;color: red;"></td>
        </tr>
        <tr>
            <td class="tds"><label for="username">用户名：</label></td>
            <td>
                <input type="text" name="username" id="username" onblur="usernameBlur(this)"/>
                <span style="color: red" id="username_msg"></span>
            </td>
        </tr>
        <tr>
            <td class="tds"><label for="password">密码：</label></td>
            <td>
                <input type="password" name="password" id="password" onblur="checkNull('password', '密码不能为空')"/>
                <span style="color: red" id="password_msg"></span>
            </td>
        </tr>
        <tr>
            <td class="tds"><label for="password2">确认密码：</label></td>
            <td>
                <input type="password" name="password2" id="password2" onblur="checkNull('password2', '确认密码不能为空');isEqual('password', '两次密码输入不一致');"/>
                <span style="color: red" id="password2_msg"></span>
            </td>
        </tr>
        <tr>
            <td class="tds"><label for="nickname">昵称：</label></td>
            <td>
                <input type="text" name="nickname" id="nickname" onblur="checkNull('nickname', '昵称不能为空')"/>
                <span style="color: red" id="nickname_msg"></span>
            </td>
        </tr>
        <tr>
            <td class="tds"><label for="email">邮箱：</label></td>
            <td>
                <input type="text" name="email" id="email" onblur="checkNull('email', '邮箱不能为空')"/>
                <span style="color: red" id="email_msg"></span>
            </td>
        </tr>
        <tr>
            <td class="tds"><label for="phone">手机号：</label></td>
            <td>
                <input type="text" name="phone" id="phone" onblur="checkNull('phone', '手机号不能为空')"/>
                <span style="color: red" id="phone_msg"></span>
            </td>
        </tr>
        <tr>
            <td class="tds"><label for="code">验证码：</label></td>
            <td>
                <input type="text" name="code" id="code" /><br/>
                <img src="code" onclick="this.src=this.src+'?'+Math.random()" id="img"><br/>
                <!--<span style="color: red" id="valistr_msg"></span>-->
            </td>
        </tr>
        <tr>
            <td class="sub_td" colspan="2" >
                <pre>        <button class="button" style="vertical-align:middle" onclick="sub()" ><span>注册 </span></button></pre>
            </td>
        </tr>
    </table>
</form>
</body>
<script>
    function sub(){

        $.ajax({
            url:"addUser",
            type:"post",
            data:$("#myForm").serialize(),
            dataType:"json",
            success:function(data){
                console.log(data)
                alert(data.message)
                if(data.code==200){
                    location.href="regist_success.html"
                }else{
                    alert(111)
                }


            },error:function (){
                alert("注册成功")
                location.href="regist_success.html"

            }

        })
    }


</script>
</html>